package org.example.controller.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Employee;
import org.example.result.Result;
import org.example.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/zhanhao")
@Slf4j
@Api(tags = "账号相关接口")
public class EmployeezhanhaoController {


    @Autowired
    EmployeeService employeeService;


    /**
     * 账号修改1
     * @param username
     * @param phone
     * @param currentPassword
     * @param newPassword
     * @param avatar
     * @param yonghuusername
     * @return
     */
    @PostMapping("/zhxg")
    @ApiOperation(value = "账号修改")
    public Result xg(@RequestParam("username") String username,
                     @RequestParam("phone") String phone,
                     @RequestParam("currentPassword") String currentPassword,
                     @RequestParam("newPassword") String newPassword,
                     @RequestPart("avatar") MultipartFile avatar
            , @RequestParam("yonghuusername") String yonghuusername) {
        if (employeeService.zhanhaoxg(avatar, username, phone, currentPassword, newPassword, yonghuusername))
            return Result.success();
        else
            return Result.error("失败");
    }


    /**
     * 账号查询
     * @param yonghuusername
     * @return
     */
    @GetMapping("/zhcx")
    @ApiOperation(value = "账号查询")
    public Result<Employee> cx(@RequestParam("yonghuusername") String yonghuusername) {
        return Result.success(employeeService.cx(yonghuusername));
    }



}
